<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$basic=$this->plugin_setting('basic');
//我的足迹
if($_RQ['op']=='main'){
	$return['params']=array();
	$return['list']=array();
	exi($return);
}
if($_RQ['op']=='getlist'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	if($_RQ['keyword']){
		$params['title like']='%'.$_RQ['keyword'].'%';
		$return['params']['title']=$_RQ['keyword'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$list=pdo_getslice('jy_wuliu_quanlog',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($list){
		$sum=count($list);
		foreach($list as &$item){
			if($item['quanid']){
				$quaninfo = pdo_get('jy_wuliu_member',array('mid'=>$item['quanid'],'uniacid'=>$_SESSION['uniacid']));
				$item['isfollow']= pdo_getcolumn('jy_wuliu_userlog',array('userid'=>$item['quanid'],'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'isfollow');
			}else{
				$quaninfo = pdo_get('jy_wuliu_sns',array('id'=>$item['snsid'],'uniacid'=>$_SESSION['uniacid']));
				$item['isfollow']= pdo_getcolumn('jy_wuliu_userlog',array('snsid'=>$item['snsid'],'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'isfollow');
			}
			$item['quaninfo']=$quaninfo;
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$member = pdo_get('core_members',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']),array('qq','nickname','avatar','birth','pcd','mobile','address'));
			$item['quaninfo']['logo']=$item['quaninfo']['logo']?tomedia($item['quaninfo']['logo']):$member['avatar'];
			$item['quaninfo']['title']=$item['quaninfo']['title']?$item['quaninfo']['title']:$member['nickname'].'的圈';
			$item['quaninfo']['pcd']=$item['quaninfo']['pcd']?$item['quaninfo']['pcd']:$member['pcd'];
			
		}
	}
	$return['list']=$list;
	$return['sum']=$sum;
	$return['params']['page'] =$pindex;
	exi($return);
}
if($_RQ['op']=='follow'){
	$postdata=get_postdata();
	$snsid = intval($postdata['snsid']);
	$mid = intval($postdata['mid']);
	if($mid ==$_SESSION['uid']){
		exi('自己不能关注自己！','error');
	}
	if($mid){
		$isfollow=pdo_getcolumn('jy_wuliu_userlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'userid'=>$mid),'isfollow');
		if($isfollow){
				pdo_update('jy_wuliu_userlog',array('isfollow'=>1,'createtime'=>TIMESTAMP),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'userid'=>$mid));
		}else{
			$insert=array(
				'uniacid'=>$_SESSION['uniacid'],
				'userid'=>$mid,
				'mid'=>$_SESSION['uid'],
				'isfollow'=>1,
				'createtime'=>TIMESTAMP
			);
			pdo_insert('jy_wuliu_userlog',$insert);
		}
	}else{
		$isfollow=pdo_getcolumn('jy_wuliu_userlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'snsid'=>$snsid),'isfollow');
		if($isfollow){
				pdo_update('jy_wuliu_userlog',array('isfollow'=>1,'createtime'=>TIMESTAMP),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'snsid'=>$snsid));
		}else{
			$insert=array(
				'uniacid'=>$_SESSION['uniacid'],
				'snsid'=>$snsid,
				'mid'=>$_SESSION['uid'],
				'isfollow'=>1,
				'createtime'=>TIMESTAMP
			);
			pdo_insert('jy_wuliu_userlog',$insert);
		}
	}
	
	exi('关注成功');
}